<template>
  <div class="goods">
    <query-form
      :queryFormItems="queryFormItems"
      @reset="resetQueryForm"
      @search="searchBtnClick"
    ></query-form>
    <query-table
      :tableConfig="goodsListTableConfig"
      pageName="goods"
      tableHeight="420"
      ref="queryTableRef"
    >
      <template #imgUrl="scope">
        <el-image
          style="width: 50px; height: 50px"
          :src="scope.row.imgUrl"
          :preview-src-list="[scope.row.imgUrl]"
          preview-teleported
          fit="cover"
        />
      </template>
      <template #createAt="scope">{{
        formatTime(scope.row.createAt)
      }}</template>
      <template #updateAt="scope">{{
        formatTime(scope.row.updateAt)
      }}</template>
      <template #status="scope">
        <el-tag v-if="scope.row.status === 1" type="success">在售</el-tag>
        <el-tag v-else type="danger">停售</el-tag>
      </template>
      <template #handle>
        <el-button type="primary" size="small" icon="Edit" text>编辑</el-button>
        <el-button type="primary" size="small" icon="Delete" text
          >删除</el-button
        >
      </template>
    </query-table>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import QueryForm from "@/components/query-form";
import QueryTable from "@/components/query-table";
import { goodsListTableConfig, queryFormItems } from "./config/config";
import { useSearchHook } from "@/hooks/useSearchHook";

export default defineComponent({
  name: "goods",
  components: {
    QueryTable,
    QueryForm
  },
  setup() {
    const [queryTableRef, resetQueryForm, searchBtnClick] = useSearchHook();
    return {
      goodsListTableConfig,
      queryFormItems,
      queryTableRef,
      resetQueryForm,
      searchBtnClick
    };
  }
});
</script>

<style scoped></style>
